ENH: parse complex special cases from stubs of unary functions#409
Merged
ev-br merged 5 commits intodata-apis:masterfrom Jan 30, 2026
Merged
ENH: parse complex special cases from stubs of unary functions#409ev-br merged 5 commits intodata-apis:masterfrom
ev-br merged 5 commits intodata-apis:masterfrom
Conversation
"stub" docstrings include "special cases":
> `if x_i is +infinity, sqrt(x_i) is +infinity` etc
`test_special_cases` parses these statements from docstrings and makes them
into tests cases.
So far, parsing only worked for real value cases, and failed for complex-valued
cases:
> For complex floating-point operands, let a = real(x_i), b = imag(x_i), and
> `If a is either +0 or -0 and b is +0, the result is +0 + 0j.`
These stanzas simply generate "case for {func} is not machine-readable" `UserWarning`s.
Quite a wall of them.
Therefore, we update parsing and testing code to take these complex-valued
cases into accout.
For now, we only consider unary functions.
The effect is:
$ ARRAY_API_TESTS_MODULE=array_api_compat.torch pytest array_api_tests/test_special_cases.py::test_unary
generates
- "128 passed, 177 warnings in 0.78s" on master
- "11 failed, 241 passed, 49 warnings in 1.82s" on this branch
So that there are new failures (from new complex-valued cases) but we 128 less warnings.
a69e65f to
158af05
Compare
158af05 to
eae7d2a
Compare
Member
Thanks @ev-br. Since it's the first such PR, I had a look - in my opinion this declaration and the level of visibility on how this code was generated is nice, and acceptable for this project. Given that this project is "advanced plumbing", I don't have any concerns about copyright, or extra review load from AI-generated contributions (you did the steering and review already). |
- Update r_complex_value regex to match ± in sign positions - Normalize ± to + in parse_complex_value() function - Detect ± symbols in parse_complex_result() to set unspecified sign flags - Results: 246 passed (+4), 45 warnings (-4) Handle spaces after ± symbol in complex value parsing Update regex to allow optional whitespace between sign and value: ([±+-]?)\s* This now handles cases like "± 0 + 0j" in addition to "±0 + 0j"
4d2eb1d to
45e566d
Compare
Member
Author
|
Thanks for the review Ralf! Let's get this in. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
"stub" docstrings include "special cases":
test_special_casesparses these statements from docstrings and makes them into tests cases.So far, parsing only worked for real value cases, and failed for complex-valued cases:
These stanzas simply generate "case for {func} is not machine-readable"
UserWarnings. Quite a wall of them.Therefore, we update parsing and testing code to take these complex-valued cases into accout.
For now, we only consider unary functions.
The effect is that
$ ARRAY_API_TESTS_MODULE=array_api_compat.torch pytest array_api_tests/test_special_cases.py::test_unarygenerates
So that there are new failures (from new complex-valued cases) but we have 128 less warnings.
NB: this pull request is generated by Copilot. The original prompt and subsequent back-and-forths are at ev-br#3